package com.onion.orm.dao;

import com.google.common.collect.Lists;
import com.onion.utils.utils.ListHelper;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class EnhancedDaoHelper {

    private static final int SPLIT_SIZE = 200;

    /**
     * 根据主键ID获取数据
     * @param ids
     * @param enhancedDao
     * @param <T>
     * @param <PK>
     * @return
     */
    public static <T,PK extends Serializable> List<T> findByIds(List<PK> ids, EnhancedDao<T, PK> enhancedDao){
        if(ids==null || ids.isEmpty()){
            return Lists.newArrayList();
        }
        List<List<PK>> splistList = ListHelper.split(ids, 200);
        List<T> listResult = new ArrayList<>(ids.size());
        for(List<PK> subList : splistList){
            List<T> curSubResult = enhancedDao.find(subList);
            listResult.addAll(curSubResult);
        }
        return listResult;
    }

}